<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ include file="../common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <title>风控统计</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon"/>
    <!-- 当前页面样式 -->
    <link rel="stylesheet" href="<s:url value="/css/common.css"/>"/>
    <!-- 当前页面样式 END -->
    <script type="text/javascript" src="<s:url value="/js/jquery-1.9.1.js" />"></script>
	<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
	<script type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
    <script type="text/javascript">
    	function checkSubmit(){
    		$("#queryRiskRuleList").attr("action","<%=basePath%>/windControllSta/queryRiskRuleList.ct");
			$("#queryRiskRuleList").submit();
    	}
    	
    	$(function(){
    		var riskLevel = $("#riskLevel").val();
    		checkMchtCd(riskLevel);
    		
    		$("#riskLevel").change(function(){
    			var riskLevel = $("#riskLevel").val();
    			checkMchtCd(riskLevel);
    		});
    		
    		function checkMchtCd(level){
        		
        		if(level == 'V'){
    				$("#tdName").show();
    				$("#tdValue").show();
    				$("#tdName1").show();
    				$("#tdValue1").show();
    				$("#addRiskRuleBtn").show();
    			}else{
    				/* alert($("#mchtCd").val()); */
    				$("#mchtCd").val("");
    				$("#posType").val("");
    				$("#tdName").hide();
    				$("#tdValue").hide();
    				$("#tdName1").hide();
    				$("#tdValue1").hide();
    				$("#addRiskRuleBtn").hide();
    				/* alert($("#mchtCd").val()); */
    			}
        	}
    		
    		
    		$(document).on("click", "#modify", function () {
                var tdArray = $(this).parent().prevAll();
                var riskNumValue = tdArray.eq(1).text();
                tdArray.eq(1).html("<input  type='text' value='"+$.trim(riskNumValue)+"' />");
                var param = $(this).next().val();
                $(this).text("提交");
                $(this).attr("id","submitUpdate");
            });
    		
    		$(document).on("click", "#submitUpdate", function () {
    			var tdArray = $(this).parent().prevAll();
                var riskNumValue = tdArray.eq(1).find("input").val();
                if(!riskNumValue){
                	alert("风控数值不能为空");
                	return false;
                }
                if(!(/^\d+(\.{0,1}\d+){0,1}$/.test(riskNumValue) )){
                	alert("请正确输入数字，只能为非负数字");
            		return false;
                }
                var paramsStr = riskNumValue + "," + $(this).next().val();
                //alert(paramsStr)
                //return false;
                $(this).text("修改");
                $(this).attr("id","modify");
                $.ajax({
                	type:"post",
                	url:"updateRiskRule.ct",
                	data:{"paramsStr":paramsStr},
                	dataType:"json",
                	success:function(result){
                		alert(result.message);
                		if(result.flag){
                			tdArray.eq(1).html($.trim(riskNumValue));
                		}
                		
                		
                	},error:function(){
                		
                	}
                	
                });
            });
    	})
    	
    	function addRiskRuleSubmit(){
    		var paramMchtCd = $.trim($("#mchtCd").val());
    		var paramRiskLevel = $.trim($("#riskLevel").val());
    		var paramsPosType = $.trim($("#posType").val());
    		if(!paramMchtCd){
    			alert("商户号为空");
    			return false;
    		}
    		
    		if(!paramsPosType){
    			alert("POS类型不能为空");
    			return false;
    		}
    		
    		$("#addRiskRuleBtn").attr("disabled",true);
    		$.ajax({
    			url:"addRiskRules.ct",
    			type:"post",
    			data:{"paramMchtCd":paramMchtCd,"paramRiskLevel":paramRiskLevel,"paramsPosType":paramsPosType},
    			dataType:"json",
    			success:function(result){
    				alert(result.resultMap.message);
    				$("#addRiskRuleBtn").attr("disabled",false);
    				if(result.resultMap.flag){
    					window.location.href="<%=basePath %>windControllSta/queryRiskRuleJsp.ct";
    				}
    				
    			},error:function(){
    				alert("操作异常");
    			}
    		});
    	}
	</script>
</head>
<body>
<s:form id="queryRiskRuleList" action="" method="post" theme="simple">
<table class="tb">
    <tbody>
        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h2">POS收单运营管理平台</div></td>
        </tr>

        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h3">风控规则管理</div></td>
        </tr>
        <tr class="tb-line">
            <td width="12%" style="min-width: 150px" align="right" class="tb-td">
                <div class="tb-h4">风控等级：</div>
            </td>
            <td class="tb-td">
                <label class="tb-input-normal"><s:select id = "riskLevel" name="searchCondition.riskLevel" list="#{'F':'未认证','E':'已认证','V':'特约商户' }"  listKey="key" listValue="value"   cssClass="queryWidth" /></label>
            </td>
            
            <td width="12%" style="min-width: 150px; display:none" align="right" class="tb-td" id="tdName">
                <div class="tb-h4">商户号：</div>
            </td>
            <td class="tb-td" style="display:none" id="tdValue"> 
                <label class="tb-input-normal"><s:textfield id="mchtCd" name="searchCondition.mchtCd" cssClass="queryWidth" /></label>
            </td>
            
         </tr>
         
         <tr class="tb-line">
            <td width="12%" style="min-width: 150px; display:none" align="right" class="tb-td" id="tdName1">
                <div class="tb-h4">POS类型：</div>
            </td>
            <td class="tb-td" style="display:none" id="tdValue1">
                <label class="tb-input-normal"><s:select id = "posType" name="searchCondition.posType" list="#{'':'请选择','1':'传统POS','2':'完美账单POS' }"  listKey="key" listValue="value"   cssClass="queryWidth" /></label>
            </td>
            
         </tr>
        <tr class="tb-line">
            <td class="tb-td line-submit" align="right" colspan="4">
                <label class="tb-input-submit">
                    <input type="button" value="查   询" onclick="return checkSubmit();"/>
                </label>
                <label class="tb-input-submit">
                    <input type="button" id= "addRiskRuleBtn" value="新增风控规则" onclick="return addRiskRuleSubmit();"/>
                </label>
            </td>
        </tr>
        <s:if test="#request.searchRsList != null && #request.searchRsList.size>0">
					<tr class="tb-line">
						<td class="tb-td paging"  align="left" colspan="4"> <page:pageCount
								max_pages="11" totalPage="${requestScope.totalPage}"
								currentPage="${requestScope.currentPage}"
								action="${rootPath}/windControllSta/queryRiskRuleList.ct?currentPage=" />

						</td>
					</tr>
	</s:if>
    </tbody>
    
</table>

<div class="big-tb">
    <table class="tb" style="width: 100%;">
        <thead>
            <tr class="tb-line">
                <th class="tb-th" colspan="14">风控规则列表</th>
            </tr>
            <tr class="tb-line bg-gray">
                		<th class="tb-th">等级</th>
						<th class="tb-th">机构号</th>
						<th class="tb-th">商户号</th>
						<th class="tb-th">商户名称</th>
						<th class="tb-th">终端号</th>
						<th class="tb-th">风控类型</th>
						<th class="tb-th">风控对象</th>
						<th class="tb-th">风控周期</th>
						<th class="tb-th">特殊类型</th>
						<th class="tb-th">计算方法</th>
						<th class="tb-th">计算单位</th>
						<th class="tb-th">风控数值</th>
						<th class="tb-th">状态标志</th>
						<th class="tb-th">操作</th>
            </tr>
        </thead>
        <tbody>
			<s:iterator value="#request.searchRsList" status="stat" id="tft">
							<tr  class="tb-line"  >
							<td class="tb-td">
							<s:property value="#tft.riskLevel"/>
							</td>
					        <td class="tb-td">
							<s:property value="#tft.riskInsCd"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskMchtCd"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.name"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskTermCd"/>
							</td>
							<td class="tb-td">
							 <s:property value="#tft.riskTransType"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskInfoTypeDesc"/>
							
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskNumCycleDesc"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskKeyTypeDesc"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskNumTypeDesc"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskNumUniteDesc"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskNumValue"/>
							</td>
							<td class="tb-td">
							<s:property value="#tft.riskUseDesc"/>
							</td>
							<td class="tb-td">
							<a id="modify">修改</a>
							<s:if test='#tft.riskLevel == "V" '>
								<input type="hidden" value="${tft.riskLevel}${','}${tft.riskInsCd}${','}${tft.riskMchtCd}${','}${tft.riskTransType}${','}${tft.riskInfoType}${','}${tft.riskNumCycle}${','}${tft.riskKeyType }${','}${tft.riskNumType}${','}${tft.riskNumUnite}">
							</s:if>
							 <s:else>
							 	<input type="hidden" value="${tft.riskLevel}${','}${tft.riskTransType}${','}${tft.riskInfoType}${','}${tft.riskNumCycle}${','}${tft.riskKeyType }${','}${tft.riskNumType}${','}${tft.riskNumUnite}">
							</s:else>
							</td>
						    </tr>
						</s:iterator>
        </tbody>
    </table>
</div>
</s:form>

<s:if test="#request.msg !=null">
		<script language="javascript">
			alert("${request.msg}");
		</script>
	</s:if>
</body>
</html>